package com.miyake.loveviewweb.client.plugin;

import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.TabPanel;

public class PluginManager extends Composite {

    public PluginManager(String filter) {
        TabPanel panel = new TabPanel();
        panel.setWidth("100%");
        initWidget(panel);

        final PluginMarket searchList = new PluginMarket(filter);
        panel.add(searchList, new HTML("Plugin Market"));
        final InstalledPluginList installedPluginList = new InstalledPluginList();
        panel.add(installedPluginList, new HTML("Installed Plugins"));
        panel.selectTab(0);
        
        for (int i = 0; i < panel.getTabBar().getTabCount(); i++) {
            panel.getTabBar().getTab(i).setWordWrap(false);
        }
        panel.addSelectionHandler(new SelectionHandler<Integer>() {

            public void onSelection(SelectionEvent<Integer> event) {
                if (event.getSelectedItem() == 0) {
                    searchList.update();
                }
                else if (event.getSelectedItem() == 1) {
                    installedPluginList.update();
                }
            }
            
        });
    }
}
